package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.wms.domain.WmsCloseAccounts;
import com.ruoyi.wms.service.IWmsCloseAccountsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 结账管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-01
 */
@RestController
@RequestMapping("/wms/closeAccounts")
public class WmsCloseAccountsController extends BaseController
{
    @Autowired
    private IWmsCloseAccountsService wmsCloseAccountsService;

    /**
     * 查询结账管理列表
     */
    @PreAuthorize(hasPermi = "wms:closeAccounts:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsCloseAccounts wmsCloseAccounts)
    {
        startPage();
        List<WmsCloseAccounts> list = wmsCloseAccountsService.selectWmsCloseAccountsList(wmsCloseAccounts);
        return getDataTable(list);
    }

    /**
     * 导出结账管理列表
     */
    @PreAuthorize(hasPermi = "wms:closeAccounts:export")
    @Log(title = "结账管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsCloseAccounts wmsCloseAccounts) throws IOException
    {
        List<WmsCloseAccounts> list = wmsCloseAccountsService.selectWmsCloseAccountsList(wmsCloseAccounts);
        ExcelUtil<WmsCloseAccounts> util = new ExcelUtil<WmsCloseAccounts>(WmsCloseAccounts.class);
        util.exportExcel(response, list, "结账管理数据");
    }

    /**
     * 获取结账管理详细信息
     */
    @PreAuthorize(hasPermi = "wms:closeAccounts:query")
    @GetMapping(value = "/{closeAccountsUuid}")
    public AjaxResult getInfo(@PathVariable("closeAccountsUuid") String closeAccountsUuid)
    {
        return AjaxResult.success(wmsCloseAccountsService.selectWmsCloseAccountsByCloseAccountsUuid(closeAccountsUuid));
    }

    /**
     * 新增结账管理
     */
    @PreAuthorize(hasPermi = "wms:closeAccounts:add")
    @Log(title = "结账管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsCloseAccounts wmsCloseAccounts)
    {
        wmsCloseAccounts.setCreateBy(SecurityUtils.getUsername());
        return toAjax(wmsCloseAccountsService.insertWmsCloseAccounts(wmsCloseAccounts));
    }

    /**
     * 修改结账管理
     */
    @PreAuthorize(hasPermi = "wms:closeAccounts:edit")
    @Log(title = "结账管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsCloseAccounts wmsCloseAccounts)
    {
        return toAjax(wmsCloseAccountsService.updateWmsCloseAccounts(wmsCloseAccounts));
    }

    /**
     * 删除结账管理
     */
    @PreAuthorize(hasPermi = "wms:closeAccounts:remove")
    @Log(title = "结账管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{closeAccountsUuids}")
    public AjaxResult remove(@PathVariable String[] closeAccountsUuids)
    {
        return toAjax(wmsCloseAccountsService.deleteWmsCloseAccountsByCloseAccountsUuids(closeAccountsUuids));
    }
}
